<?php

$this->extend('/Common/admin_index');

$this->Html
	->addCrumb('', '/admin', array('icon' => 'home'))
	->addCrumb(__('Countries'), array('action' => 'index'));

echo $this->Form->create('Country',
	array('url' => array('controller' => 'countries', 'action' => 'process')),
	array('class' => 'form-inline')
);
$limit_fields = json_decode(Configure::read('Countries.country_fields'));
?>
<table class="table table-striped">
<?php
	if(in_array('code',$limit_fields)){
		$tableHeaders = $this->Html->tableHeaders(array(
			'',
			$this->Paginator->sort('id'),
			$this->Paginator->sort('name'),
			$this->Paginator->sort('alias'),
			$this->Paginator->sort('code'),
			$this->Paginator->sort('city_count'),
			$this->Paginator->sort('status'),
			__('Actions'),
		));
	}else{
		$tableHeaders = $this->Html->tableHeaders(array(
			'',
			$this->Paginator->sort('id'),
			$this->Paginator->sort('name'),
			$this->Paginator->sort('alias'),
			$this->Paginator->sort('city_count'),
			$this->Paginator->sort('status'),
			__('Actions'),
		));	
	}
?>
	<thead>
		<?php echo $tableHeaders; ?>
	</thead>
<?php
	$rows = array();
	foreach ($countries as $country) {
		$actions = array();
		$actions[] = $this->Croogo->adminRowAction('',
			array('controller' => 'countries', 'action' => 'moveup', $country['Country']['id']),
			array('icon' => 'arrow-up', 'tooltip' => __('Move up'),
		));
		$actions[] = $this->Croogo->adminRowAction('',
			array('controller' => 'countries', 'action' => 'movedown', $country['Country']['id']),
			array('icon' => 'arrow-down', 'tooltip' => __('Move down'),
			)
		);
		$actions[] = $this->Croogo->adminRowActions($country['Country']['id']);
		$actions[] = $this->Croogo->adminRowAction('',
			array('controller' => 'countries', 'action' => 'edit', $country['Country']['id']),
			array('icon' => 'pencil', 'tooltip' => __('Edit this item'))
		);
		$actions[] = $this->Croogo->adminRowAction('',
			'#Country' . $country['Country']['id'] . 'Id',
			array('icon' => 'trash', 'tooltip' => __('Remove this item'), 'rowAction' => 'delete'),
			__('Are you sure?')
		);

		$actions = $this->Html->div('item-actions', implode(' ', $actions));

		if(in_array('code',$limit_fields)){
			$rows[] = array(
				$this->Form->checkbox('Country.' . $country['Country']['id'] . '.id'),
				$country['Country']['id'],
				$this->Html->link($country['Country']['name'], array('controller' => 'countries', 'action' => 'edit', $country['Country']['id'])),
				$country['Country']['alias'],
				$country['Country']['code'],
				$country['Country']['city_count'],			
				$this->element('admin/toggle', array(
					'id' => $country['Country']['id'],
					'status' => $country['Country']['status'],
				)),
				$actions,
			);		
		}else{
			$rows[] = array(
				$this->Form->checkbox('Country.' . $country['Country']['id'] . '.id'),
				$country['Country']['id'],
				$this->Html->link($country['Country']['name'], array('controller' => 'countries', 'action' => 'edit', $country['Country']['id'])),
				$country['Country']['alias'],
				$country['Country']['city_count'],			
				$this->element('admin/toggle', array(
					'id' => $country['Country']['id'],
					'status' => $country['Country']['status'],
				)),
				$actions,
			);		
		}
	}

	echo $this->Html->tableCells($rows);
?>
</table>
<div class="row-fluid">
	<div id="bulk-action" class="control-group">
		<?php
			echo $this->Form->input('Country.action', array(
				'label' => false,
				'div' => 'input inline',
				'options' => array(
					'publish' => __('Publish'),
					'unpublish' => __('Unpublish'),
					'delete' => __('Delete'),
				),
				'empty' => true,
			));
		?>
		<div class="controls">
			<?php echo $this->Form->end(__('Submit')); ?>
		</div>
	</div>
</div>